package com.liangtian.mdm.dm.jsp.controller;

import com.liangtian.mdm.base.controller.BaseController;
import com.liangtian.mdm.base.utils.ResultObject;
import com.liangtian.mdm.dm.jsp.service.JspExpImpService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/***
 *  动态模型导入导出
 * @author wy
 *
 */

@Controller
@RequestMapping("/jspExpImpAction")
public class JspExpImpActionController extends BaseController {

    @Autowired
    private JspExpImpService jspExpImpService;

    /**
     * 导出动态模型的模板
     *
     * @param modelId
     * @param tableName
     * @return
     */
    @RequestMapping(value = "tempExport", method = RequestMethod.GET)
    @ResponseBody
    public void templeExport(HttpServletResponse response, HttpServletRequest request) {
        String modelId = request.getParameter("modelId");
        //	DisManager.queryDisData("1761","","XML");
        jspExpImpService.ExportModelExcelInfo(modelId, response);
    }

    @RequestMapping(value = "excelImport", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject excelImport(HttpServletResponse response, HttpServletRequest request) {
        String modelId = request.getParameter("modelId");
        ResultObject result = null;
        try {
            String err_fileName = jspExpImpService.importModelExcelInfo(modelId, request, response);
            result = new ResultObject(StringUtils.isEmpty(err_fileName) ? true : false, err_fileName);
        } catch (Exception e) {
            result = new ResultObject(false, "导入失败!");
        }

        return result;
    }

    @RequestMapping(value = "dis", method = RequestMethod.POST)
    @ResponseBody
    public void dis() {
//    	DisManager.queryDisData("1761");
    }
}
